package com.mdx.zhizhao.controller;

import com.mdx.zhizhao.domain.Enterprise;
import com.mdx.zhizhao.domain.Response;
import com.mdx.zhizhao.service.EnterpriseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.hateoas.Link;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin(origins = "http://localhost:5173")
@RequestMapping(value = "/enterprise" ,produces = {MediaType.APPLICATION_JSON_VALUE,MediaType.APPLICATION_XML_VALUE})
public class EnterpriseController {
    @Autowired
    private EnterpriseService enterpriseService;
     @PostMapping("/login")
    public Response<Enterprise> login(@RequestBody Enterprise enterprise){
        Enterprise enterprise1 = enterpriseService.login(enterprise.getEnterpriseid(),enterprise.getEnterprisepassword());
        Response<Enterprise> response =new Response<>();
        response.setData(enterprise1);
        if(enterprise1 == null){
            response.f(null,"账号或密码错误");
        }else {
            response.s(enterprise1,"登陆成功");
        }
        return response;
    }
    @PostMapping("/signup")
    public Response<Enterprise> signup(@RequestBody Enterprise enterprise){
        enterpriseService.signup(enterprise);
        Response<Enterprise> response =new Response<>();
        response.s(enterprise,"成功");
        return response;
    }
    @PostMapping("/updateEnterprise")
    public Response<Enterprise> updateEnterprise(@RequestBody Enterprise enterprise){
        enterpriseService.updateEnterprise(enterprise);
        Response<Enterprise> response =new Response<>();
        response.s(enterprise,"成功");
        return response;
    }
    @GetMapping("/{id}")
    public Response<Enterprise> selectEnterprise(@PathVariable String id){
        Enterprise enterprise = enterpriseService.selectEnterprise(id);
        Response<Enterprise> response =new Response<>();
        if(enterprise == null){
            response.f(null,"无此用户");
        }else {
            response.s(enterprise,"成功");
        }
        return response;
    }
}
